package org.game.view;

import java.util.TimerTask;

import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.Canvas;
import android.view.View;

public class Timer extends View {
	private String timeImageFile;
	private int countdown;
	private Bitmap timeImage;
	private java.util.Timer countTimer;
	
	public Timer(Context context) {
		super(context);
		
	}
	public Timer(Context context,String timeImageFile,int countdown) {
		super(context);
		this.timeImageFile=timeImageFile;
		this.countdown=countdown;
	}
	public Timer(Context context,Bitmap timeImage,int countdown) {
		super(context);
		this.timeImage=timeImage;
		this.countdown=countdown;
	}
	
	public void draw(Canvas canvas){
		//canvas.drawBitmap(timeImage, 0, 0, null);
		canvas.drawText(String.valueOf(countdown), 10,64,null);
	}
	public void startCountdown(){
		countTimer=new java.util.Timer();
		countTimer.schedule(new CountdownTask(), 0,1000);
	}
	public class CountdownTask extends TimerTask{
		@Override
		public void run() {
			countdown--;
			if(countdown==0){
				countTimer.cancel();
			}
		}
	}
}

